﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using ReferralTracker.Data.Contexts;

namespace ReferralTracker.Data.Repositories {
    public abstract class Repository <TEntity> : IRepository<TEntity> where TEntity : class {
        protected IContext _context = null;
        protected IDbSet<TEntity> _data = null;

        public Repository(IContext context) {
            _context = context;
            _data = context.Set<TEntity>();
        }

        public virtual void Add(TEntity entity) {
            _data.Add(entity);
        }

        public virtual void Delete(TEntity entity) {
            _data.Remove(entity);
        }

        public TEntity FindByKey(params object[] keyValues) {
            return _data.Find(keyValues);
        }

        public virtual IList<TEntity> SelectAll() {
            return _data.ToList();
        }

        public virtual int GetCount() {
            return _data.Count();
        }
    }
}
